package cn.rongdao.jrkabao.model.login;

import com.mifengkong.frtools.http.request.HttpFunction;
import com.mifengkong.frtools.util.FRString;

import java.util.Map;

import cn.rongdao.jrkabao.bean.login.UserBean;
import cn.rongdao.jrkabao.model.api.BaseKaMaoModel;
import io.reactivex.Observable;
import io.reactivex.Observer;

/**
 * Created by jack on 17/5/5
 */

public class LoginModel extends BaseKaMaoModel {

    public static LoginModel getInstance() {
        return getPresent(LoginModel.class);
    }

    public LoginModel addParams(String key, Object value) {
        if (!FRString.isEmpty(key)) {
            mParams.put(key, FRString.valueOf(value));
        }
        return this;
    }

    public LoginModel addParams(Map<String, String> map) {
        if (null != map && map.size() > 0) {
            mParams.putAll(map);
        }
        return this;
    }

    public void execute(Observer<UserBean> observer) {
        Observable<UserBean> observable = mServletApi.getLoginInfo(mParams).map(new HttpFunction<UserBean>());
        toSubscribe(observable, observer);
    }

    @Override
    protected String[] loginUrl() {
        return new String[]{"User/loginByPassword"};
    }
}